import './App.scss';
import 'antd/dist/reset.css';
import Index from './layout/Index'
import Login from './views/login/Index'

import { Routes, Route, Navigate, useLocation } from 'react-router-dom'

// 获取 redux 里面的登录状态
import { useAppSelector } from "./store/hooks";

function App() {
  // 拿到登录状态，导航守卫在 React 中不需要，直接在对应需要的地方直接写逻辑即可
  const loginState = useAppSelector(state => state.user.loginState)

  const { search } = useLocation() // ?r=/pro/list// +++++++++++
  const redirectUrl = search.split('?r=')[1] // +++++++++++
  const str = redirectUrl ? redirectUrl : '/'// +++++++++++

  return (
    <>
      <Routes>
        <Route path='/login' element={loginState ? <Navigate to={str} /> : <Login />}></Route>
        <Route path='/*' element={loginState ? <Index></Index> : <Navigate to='/login'></Navigate>}></Route>
      </Routes>
    </>
  );
}

export default App;
